//
//  homeViewController.m
//  zhangGuangTianXia
//
//  Created by tangtangchitangtang on 2017/11/7.
//  Copyright © 2017年 tangtangchitangtang. All rights reserved.
//

#import "homeViewController.h"
#import "homeView.h"
@interface homeViewController ()<UITextFieldDelegate>

@property(nonatomic,strong)homeView *aView;
@property(nonatomic,strong)UITextField *souShuoLabel;


@end

@implementation homeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self wr_setNavBarBackgroundAlpha:0];
    
    _aView=[homeView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
    }];
    [_aView creatView];
    _aView.viewController=self;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [self creatLeftBtn];
}

-(void)creatLeftBtn{

//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//    NSDictionary *dic = [defaults objectForKey:@"dingWei"];

//    CGSize size= [ZQTools getNSStringWeight:[NSString stringWithFormat:@"%@",[dic objectForKey:@"cityName"]] andViewWight:17 andFont:15];
     CGSize size= [ZQTools getNSStringWeight:@"重庆" andViewWight:17 andFont:15];


    UIView * viewBackInNavi=[[UIView alloc]initWithFrame:CGRectMake(0, 0, size.width+35, 20)];
    viewBackInNavi.backgroundColor=[UIColor clearColor];
    viewBackInNavi.userInteractionEnabled=YES;
    //重做按钮
    UIButton *myRightRePaintBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, size.width+35, 20)];
//    [myRightRePaintBtn addTarget:self action:@selector(pushToDiZhi:) forControlEvents:UIControlEventTouchUpInside];
    [myRightRePaintBtn setBackgroundColor:[UIColor clearColor]];
    [myRightRePaintBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
//    [myRightRePaintBtn setTitle:[NSString stringWithFormat:@"%@",[dic objectForKey:@"cityName"]] forState:UIControlStateNormal];

    [myRightRePaintBtn setTitle:@"重庆" forState:UIControlStateNormal];
    [myRightRePaintBtn setImage:[UIImage imageNamed:@"坐标-拷贝"] forState:UIControlStateNormal];
    [myRightRePaintBtn setTitleColor:ColorWithRGB(49, 49, 49) forState:UIControlStateNormal];
    myRightRePaintBtn.titleLabel.adjustsFontSizeToFitWidth=YES;

    [myRightRePaintBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
    CGFloat labelWidth = myRightRePaintBtn.titleLabel.frame.size.width;
    CGFloat imageWith =myRightRePaintBtn.imageView.frame.size.width;
    myRightRePaintBtn.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);
    myRightRePaintBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWith, 0, imageWith);


    [viewBackInNavi addSubview:myRightRePaintBtn];


    UIBarButtonItem * right=[[UIBarButtonItem alloc]initWithCustomView:viewBackInNavi];
    //将整个viewBackInNavi右移10
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    negativeSpacer.width =-20;//负数为右移，正数为左移

    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,right, nil];


    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _mainW-size.width-75, 35)];//allocate titleView
    [titleView setBackgroundColor:_LightGrey];
    titleView.layer.cornerRadius=35/2;

    UIImageView *souShuoImage=[UIImageView new];
    [titleView addSubview:souShuoImage];
    [souShuoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(5);
        make.width.height.mas_equalTo(20);
    }];
    souShuoImage.image=[UIImage imageNamed:@"搜索"];

    _souShuoLabel=[UITextField new];
    [titleView addSubview:_souShuoLabel];
    [_souShuoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(souShuoImage.mas_right).mas_equalTo(10);
        make.right.mas_equalTo(-10);
    }];
    _souShuoLabel.placeholder=@"搜索景区名";
    _souShuoLabel.font=[UIFont systemFontOfSize:14];
    _souShuoLabel.delegate=self;
    _souShuoLabel.returnKeyType= UIReturnKeyDone;



    self.navigationItem.titleView = titleView;



//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"搜索" style:UIBarButtonItemStylePlain target:self action:@selector(sousuo)];

}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{

    if ([[[UITextInputMode currentInputMode]primaryLanguage] isEqualToString:@"emoji"]) {
        return NO;
    }
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [_souShuoLabel resignFirstResponder];
//    [self sousuo];
    return YES;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
